<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="huoyun" uri="/huoyun"%>
<%@ taglib uri="/struts-tags" prefix="s"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
	<head>
		<title>发布货源信息</title>

		<meta http-equiv="pragma" content="no-cache">
		<meta http-equiv="cache-control" content="no-cache">
		<meta http-equiv="expires" content="0">
		<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
		<meta http-equiv="description" content="This is my page">

		<link rel="stylesheet" type="text/css"
			href="${pageContext.request.contextPath}/theme/css/main.css">
		<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/theme/css/dialog.css">
		<link rel="stylesheet" type="text/css"
			href="${pageContext.request.contextPath}/theme/css/style_userCenter.css">
		<script type="text/javascript"
			src="${pageContext.request.contextPath}/theme/js/jquery-1.6.js"></script>
	    <script type="text/javascript" src="${pageContext.request.contextPath}/theme/js/dialog.js"></script>
		<script type="text/javascript"
			src="${pageContext.request.contextPath}/theme/js/jquery.form.js"></script>
		<script type="text/javascript"
			src="${pageContext.request.contextPath}/theme/js/calendar/WdatePicker.js"></script>
		<script type="text/javascript"
			src="${pageContext.request.contextPath}/theme/js/jquery.validate.js"></script>
		<script type="text/javascript"
			src="${pageContext.request.contextPath}/theme/js/additional-methods.js"
			charset="utf-8"></script>
	</head>
	<body>
		<div>
			<jsp:include page="../userAdmin/nav.jsp">
				<jsp:param value="nav_main" name="nav" />
			</jsp:include>
		</div>
		<div class="realCer">
			<!--主体部分-->
			<div class="realMain clearfix mt10">
				<!--左侧菜单-->
				<div class="realLeft" id="meunLeft">
					<jsp:include page="../userAdmin/leftMenu.jsp">
						<jsp:param value="con_nav_main" name="con_nav" />
						<jsp:param value="cargoManagement" name="selectMenu" />
					</jsp:include>
				</div>
				<!--中间-->
				<div class="realRight ml10">
					<div class="box">
						<div class="tit">
							<strong>修改货源</strong>
						</div>
						<div class="con">
							<div style="color: red; margin-left: 100px;">
								<s:property value="resultMsg" />
								<s:fielderror></s:fielderror>
							</div>
							<div class="form_wrap clearfix">
								<form method="post" id="cargoForm" name="cargoForm" action="editInvoice.action" namespace="/cargo">
									<input type="hidden" name="hasInvoice" id="hasInvoice" value="" />
									<input type="hidden" name="invoice.id" value="<s:property value="invoice.id"/>"/>
									<table class="tableForm addCargo" style="width:100%">
										<tbody>
											<!-- <tr>
												
												<td class="tdValue" colspan="2">
													<input type="checkbox" id="changeInsurance"
														onclick="changeBuyInsurance();"/>
													购买保险
													<input type="hidden" name="buyInsurance" id="buyInsurance"
														value="no" />
												</td>
											</tr>
											<tr id="buyInsuranceDisplay" style="display: none">
												<td>
													<table class="tableForm">
														<tr>
															<td colspan="2">
																<h2>
																	保险信息
																</h2>
															</td>
														</tr>
														<tr>
															<td class="tdLabel" width="100">
																保险种类：
															</td>
															<td class="tdValue">
																<input class="text" type="text" name="insuranceType"
																	id="insuranceType" style="width: 180px" />
															</td>
														</tr>
														<tr>
															<td class="tdLabel">
																投保货值 ：
															</td>
															<td class="tdValue">
																<input class="text" type="text" name="insuranceValue"
																	id="insurancevalue" style="width: 180px" />
															</td>
														</tr>
														<tr>
															<td class="tdLabel">
																投保金额 ：
															</td>
															<td class="tdValue">
																<input class="text" type="text" name="insuranceCost"
																	id="insuranceCost" style="width: 180px" />
															</td>
														</tr>
													</table>
												</td>
											</tr> -->
											<!--  <tr>
												
												<td class="tdValue" colspan="2">
													<input type="checkbox" id="changeInvoice"
														onclick="makeInvoice()"/>
													发票
													<input type="hidden" name="invoiceValue" id="invoiceValue" value="no" />
												</td>
											</tr>-->
										<tr>
											<td colspan="2">
												<h2>发票信息</h2>
											</td>
										</tr>
										<tr>
											<td class="tdLabel" width="120">
												发票抬头:
											</td>
											<td class="tdValue">
												<input type="text" class="text" name="invoice.title" value="<s:property value="invoice.title"/>"/>
											</td>
										</tr>
										<tr id="addressHead" >
											<td class="tdLabel" width="120">
												选择联系地址:
											</td>
											<td class="tdValue">
												<table class="listTable" id="address_list_table">
													<tr>
														<th>序号</th>
														<th>收货人</th>
														<th>所在区域</th>
														<th>详细地址</th>
														<th>邮编号码</th>
														<th>座机/手机号码</th>
														<th>操作</th>
													</tr>
													<s:iterator var="varAddress" value="addressList" status="st">
														<tr id="line_<s:property value="#varAddress.id"/>">
															<td>
																 <input type="radio" <s:if test="#varAddress.type == 1"> checked="checked" </s:if> name="invoice.addressId" value="<s:property value="#varAddress.id"/>">&nbsp;
															</td>
															<td>
																<s:property value="#varAddress.username" />
															</td>
															<td>
																<huoyun:regionSelect provinceValue="${varAddress.province }"
															cityValue="${varAddress.city }" townValue="${varAddress.town }" type="view"/>
															</td>
															<td>
																<s:property value="#varAddress.address" />
															</td>
															<td>
																<s:property value="#varAddress.postalCode" />
															</td>
															<td>
																<s:property value="#varAddress.telephone" />
																/
																<s:property value="#varAddress.mobilePhone" />
															</td>
															<td>
																<a href="javascript:void(0);" onclick="modifyAddress('<s:property value="#varAddress.id"/>')">修改</a>&nbsp;|&nbsp;
																<a href="javascript:void(0);" onclick="deleteAddress('<s:property value="#varAddress.id"/>')">删除</a>
															</td>
														</tr>
													</s:iterator>
												</table>
												<div class="button button-swhite" style="margin-top: 10px; margin-bottom: 20px;">
													<input type="button" onclick="addAddress();" value="添加新地址" class="button-text">
												</div>
											</td>
										</tr>
										<tr>
											<td class="tdLabel"></td>
											<td class="tdValue">
												<span class="button button-lorange">
													<input id="button_submit" onclick="saveInvoice()" type="button" value="保存" class="button-text">
												</span>
												<span class="button button-lorange">
													<input id="button_submit" onclick="overLeap()" type="button" value="跳过并保存" class="button-text">
												</span>
											</td>
										</tr>
									</tbody>
									</table>
								</form>
<script type="text/javascript">	
	$(function(){
		var addressId = '<s:property value="invoice.addressId"/>';
		
		if(addressId != "")
		{
			$("input[name='invoice.addressId'][value='" + addressId +"']")[0].attr("checked", "checked");
		}
	});
	function addAddress()
	{	
		$.ajax({
			type : "post",
			url : "${pageContext.request.contextPath}/ajaxAddress/preAddAddress.action",
			data : {},
			dataType : "html",
			success : function(data) {
				simpleBox.open({type:'html',value:data}, {title:'发票邮寄地址'}, {fixed:false});
			}
		});								
	}
	
	function overLeap(){
		$("#hasInvoice").val("no");
		$("#cargoForm").submit();
	}
	
	function saveInvoice(){
		var valid = $("#cargoForm").validate({
				errorPlacement: function(error, element) {
					    // element.parent("td").append(error);
					     element.attr("title", error.html());
					   },
				rules : {
					"invoice.title":
	  				{
	  					required: true
	  				},
	  				"invoice.address":
	  				{
	  					required: true
	  				}
				},
				messages : {
					"invoice.title":
	  				{
	  					required: "必填项"
	  				},
	  				
	  				"invoice.address":
	  				{
	  					required: "请选择一个邮寄地址"
	  				}
				}
			});
		if(valid.form()==true){
			$("#hasInvoice").val("yes");
			$("#cargoForm").submit();
		}
	}
	
	function deleteAddress(addressId)
	{	
		$.ajax({
			type : "post",
			url  : "${pageContext.request.contextPath}/ajaxAddress/ajaxDelAddress.action",
			data : {
				addressId : addressId
			},
			success : function(data){
				$("#line_"+addressId).remove();
			}
		});
	}
	
    function modifyAddress(addressId){
    	$.ajax({
    		type : "post",
    		url  : "${pageContext.request.contextPath}/ajaxAddress/ajaxPreModifyAddress.action",
    		data : {
    			addressId : addressId
    		},
    		dataType : "html",
    		success : function(data)
    		{
    			simpleBox.open({type : 'html', value : data},{title : '修改邮寄地址'},{fixed:false});
    		}
    	});
    }
	
	</script>							
							</div>

						</div>
					</div>
				</div>
				<!--中间-->
			</div>
		</div>

		<div>
			<jsp:include page="/footer.jsp"></jsp:include>
		</div>
	</body>
</html>
